package com.lw.tcpdemo;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * @author LW
 * @2020/9/13 22:40
 */
public class AutoCloseIOClient {

    public static void main(String[] args) throws UnknownHostException {
        //1.要知道服务器的地址
        InetAddress serverIP = InetAddress.getByName("127.0.0.1");
        //端口号
        int port = 9999;
        try(Socket socket = new Socket(serverIP,port);OutputStream os = socket.getOutputStream()) {

            os.write("学习TCP,1.8,try---括号中---自动关闭IO".getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
